﻿using System;
using System.Linq;

namespace YiJing.Model
{
    public static class Extensions
    {
        public static Line ToLine(this CoinSet toss)
        {
            var n = toss.HeadsCount * 3 + toss.TailsCount * 2;
            return new Line
            {
                IsBroken = n % 2 == 0,
                IsMoving = n % 3 == 0
            };
        }

        public static HexagramFigure ToHexagram(this CoinSet[] sequence)
        {
            Guard.Against<ArgumentException>(sequence == null || sequence.Length < HexagramFigure.MaxLines, "sequence");
// ReSharper disable AssignNullToNotNullAttribute
            return new HexagramFigure(sequence.Take(HexagramFigure.MaxLines).Select(ToLine));
// ReSharper restore AssignNullToNotNullAttribute
        }
    }
}
